import { defineStore } from "pinia";
import Axios from "axios";
// import { useUser } from "user.js";  // 假设存在这个文件

const useContent = defineStore("content", {
  state: () => {
    return {
      name: "tom",
      age: 18,
      user: [
        { id: 1, name: "tom" },
        { id: 2, name: "jack" },
        { id: 3, name: "jerry" },
      ],
      content: {},
    };
  },
  getters: {
    doubleAge(state) {
      return state.age * 2;
    },
    doubleAgeAddOne(state) {
      return this.doubleAge + 1; //使用其他getter的数据

      //   return useUser.id  //使用其他store的数据
    },
    getUserName(state) {
      return (userId) => state.user.find((user) => user.id === userId).name;
    },
  },
  actions: {
    async getContent() {
      const data = await Axios.get("http://localhost:3003/news");
      this.content = data.data;
    },
  },
});

export default useContent;
